//
//  WalletViewController.m
//  SeaMelonSeeds_Counselor
//
//  Created by 尤振宇 on 2017/7/25.
//  Copyright © 2017年 杨笑. All rights reserved.
//

#import "WalletViewController.h"
#import <WXApi.h>
#import "AppDelegate+WXApi.h"
#import "ConsultantInformation.h"
#import "BillingDetailsViewController.h"

@interface WalletViewController () <WXApiDelegate>
@property (weak, nonatomic) IBOutlet UILabel *label;
@property (weak, nonatomic) IBOutlet UIButton *withdrawalBtn;//提现
@property (weak, nonatomic) IBOutlet UIButton *bankCardBtn;

@property(nonatomic,assign) BOOL request;
@end

@implementation WalletViewController

-(instancetype)init
{
    return [[UIStoryboard storyboardWithName:@"Wallet" bundle:nil] instantiateViewControllerWithIdentifier:@"WalletViewController"];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"我的钱包";
    [self.withdrawalBtn roundedCorners_5PX];
    
    [self.bankCardBtn roundedCorners_5PX];
    [self.bankCardBtn borderWidthAndColor:k65ACFE];
    
    self.navigationItem.rightBarButtonItem = [Tool BarButtonItemWithTitle:@"明细" target:self action:@selector(rightAction)];
    
    [self loadData];
    // Do any additional setup after loading the view.
}

-(void)rightAction
{
    [self pushViewController:[BillingDetailsViewController new] animated:YES];
}

- (IBAction)bankCarkAction:(id)sender {
    
    if ([WXApi isWXAppSupportApi]) {
        //构造SendAuthReq结构体
        SendAuthReq *req =[[SendAuthReq alloc]init];
        req.scope = @"snsapi_userinfo";
        req.state = @"7521";
//        req.openID = WXAPPID;
        //第三方向微信终端发送一个SendAuthReq消息结构
        //    BOOL is = [WXApi sendAuthReq:req viewController:self delegate:self];
        BOOL is = [WXApi sendReq:req];
        if (!is) {
            
        }
    }else{
        [MBProgressHUD showError:@"请先更新微信"];
    }

}



-(void)loadData
{
     //请求成功 self.request set yes
    ConsultantInformation *info = [ConsultantInformation sharedInformation];
    NSString *balance = [NSString stringWithFormat:@"%.2f",info.balance];
    NSArray *arr = [balance componentsSeparatedByString:@"."];
    
    NSMutableAttributedString *str = [NSMutableAttributedString new];
    [str appendAttributedString:[[NSAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@.",arr[0]] attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:24],NSForegroundColorAttributeName:[@"F6415E" colorWithHexString]}]];
    [str appendAttributedString:[[NSAttributedString alloc]initWithString:arr[1] attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16],NSForegroundColorAttributeName:[@"F6415E" colorWithHexString]}]];
    [str appendAttributedString:[[NSAttributedString alloc]initWithString:@"\n\n"]];
    [str appendAttributedString:[[NSAttributedString alloc]initWithString:self.label.text attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16],NSForegroundColorAttributeName:self.label.textColor}]];
    self.label.attributedText = str;
    
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    [style setLineSpacing:16];
    [style setAlignment:NSTextAlignmentCenter];
    [str addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, str.length)];
    
    self.bankCardBtn.hidden = info.is_bind_wechat;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 PushWithdrawal
 */

//-(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
//{
//    
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
